import 'package:flutter/material.dart';
import 'package:flutter_chat_ui/pages/onnx/onnx_widgets_notifier_controller.dart';
import 'package:get/get.dart';

import 'agent_mask_oval_painter.dart';

///
/// 语音识别蒙版视图
///
class OnnxMaskView extends GetView<OnnxWidgetsNotifireController> {
  const OnnxMaskView({
    super.key,
  });

  @override
  Widget build(BuildContext context) {
    return Material(
      color: Colors.black.withOpacity(0.5),
      child: Stack(
        alignment: Alignment.bottomCenter,
        children: [
          Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              Expanded(
                child: Container(
                  margin: const EdgeInsets.only(top: 80),
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      /// 顶部录制语音波浪动画 - 完全独立的动画
                      // WaveView(),

                      /// 语音转文本，显示文本
                      Padding(
                        padding: const EdgeInsets.only(left: 24, right: 24, top: 20),
                        child: RepaintBoundary(
                          child: Obx(() {
                            return Text(
                              controller.recognizedText.value,
                              maxLines: 3,
                              softWrap: true,
                              style: const TextStyle(
                                color: Colors.white,
                                fontWeight: FontWeight.w600,
                                fontSize: 16,
                                overflow: TextOverflow.ellipsis,
                              ),
                            );
                          }),
                        ),
                      ),
                    ],
                  ),
                ),
              ),

              /// 底部圆弧背景颜色变化、文本变化。
              Obx(() {
                bool stop = controller.recordStatus.value == XRecordStatus.stopRecord ||
                    controller.recordStatus.value == XRecordStatus.pausedRecord;

                return RepaintBoundary(
                  child: CustomPaint(
                    painter: OnnxMaskOvalPainter(isFocus: !stop),
                    child: Container(
                      width: double.infinity,
                      height: kOnnxVoiceBgOvalHeight,
                      alignment: Alignment.topCenter,
                      child: Padding(
                        padding: const EdgeInsets.only(top: 20),
                        child: Text(
                          stop ? '取消 发送' : '松开 发送',
                          style: const TextStyle(
                            fontSize: 15,
                            color: Colors.black,
                            fontWeight: FontWeight.w600,
                          ),
                        ),
                      ),
                    ),
                  ),
                );
              }),
            ],
          ),
        ],
      ),
    );
  }
}
